package com.minelx.sqlstructures.statements.parse.select;

import com.minelx.sequence.core.ReturnMatcher;
import com.minelx.sequence.core.StringScanner;

import java.util.function.IntPredicate;

// FIXME 2021/7/5  wait for me!!!     ReduceMatcher
public class TableNameMatcher implements ReturnMatcher<String, StringScanner> {

	private final IntPredicate tableNamePredicate;

	public TableNameMatcher() {
		tableNamePredicate = character ->
				Character.isDigit(character) ||
				Character.isAlphabetic(character) ||
				character == '_';
	}

	@Override
	public String onMatched(StringScanner source) {
		return source.collect(tableNamePredicate);
	}

	@Override
	public boolean isMatch(StringScanner source) {
		char nextChar = source.copy().nextChar();
		return tableNamePredicate.test(nextChar);
	}
}
